<%@page import="com.mconnect.msurvey.model.Report"%>
<%@page import="com.mconnect.msurvey.model.User"%>
<%@page import="com.mconnect.msurvey.controller.PlanManager"%>
<%@page import="com.mconnect.msurvey.controller.UserManager"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
	 <style>
		body { font-size: 62.5%; }
		label, input { display:block; }
		input.text { margin-bottom:12px; width:95%; padding: .4em; }
		fieldset { padding:0; border:0; margin-top:25px; }
		h1 { font-size: 1.2em; margin: .6em 0; }
		div#users-contain { width: 350px; margin: 20px 0; }
		div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
		div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
	</style>

</head>
<body>
	<% int id_plan = Integer.parseInt(request.getParameter("id_plan")); 
	String dateFrom = request.getParameter("dateFrom");
	String dateTo = request.getParameter("dateTo");
	String agree = request.getParameter("agree");
		List<User> userList = new ArrayList<User>();
		UserManager uM = new UserManager();
		userList = uM.getUserById_plan(id_plan);
		PlanManager pM = new PlanManager();
		
		int sumOfSurveys = 0, sumOfSurveysHr = 0, sumOfTotalSurveys =0, sumOfConfirms =0, sumOfRecommend = 0, sumOfRecommendHR = 0, sumOfTotalRecommend = 0, sumOfPesels = 0;
		
	%>
	
		<div id="users-contain" class="ui-widget" style="width: 915px; ">
		<table id="users" class="ui-widget ui-widget-content" >
			<thead>
				<tr class="ui-widget-header ">
					<th style="width: 150px;"></th>
					<th style="width: 85px;">Ankiet</th>
					<th style="width: 85px;">Ankiet HR</th>
					<th style="width: 85px;">Wszystkich ankiet</th>
					<th style="width: 85px;">Poleceń</th>
					<th style="width: 85px;">Poleceń HR</th>
					<th style="width: 85px;">Wszystkich poleceń</th>
					<th style="width: 85px;">Realizacja planu</th>
					<th style="width: 85px;">Potwierdziło przybycie</th>
					<th style="width: 85px;">Pozyskanych peseli</th>
				</tr>
			<tbody>
				<% for(User user: userList){
					Report report = pM.getReportByIdUserAndIdPlan(user.getId_user(), id_plan, dateFrom, dateTo, agree);
					int numberOfSurveys = report.getNumberOfSurveys();
					int numberOfSurveysHR = report.getNumberOfSurveysHR();
					int totalSurveys = report.getTotalSurveys();
					int numberOfConfirms = report.getNumberOfConfirms();
		    		double realizationPlan = pM.getRealizationOfPlan(numberOfConfirms, numberOfSurveys);
		    		int numberOfRecommend = report.getNumberOfRecommend();
		    		int numberOfRecommendHR = report.getNumberOfRecommendHr();
		    		int totalRecommend = report.getTotalRecommend();
		    		int numberOfPesels = report.getNumberOfPesels();
		    		sumOfSurveys += numberOfSurveys;
		    		sumOfSurveysHr += numberOfSurveysHR;
		    		sumOfTotalSurveys += totalSurveys;
		    		sumOfConfirms += numberOfConfirms;
		    		sumOfRecommend += numberOfRecommend;
		    		sumOfRecommendHR += numberOfRecommendHR;
		    		sumOfTotalRecommend += totalRecommend;
		    		sumOfPesels += numberOfPesels;
		    		
				%>
					<tr>
						<td><%= user.getFirstname() + " " + user.getLastname() %></td>
						<td><%= numberOfSurveys %></td>
						<td><%= numberOfSurveysHR %></td>
						<td><%= totalSurveys %></td>
						<td><%= numberOfRecommend %></td>
						<td><%= numberOfRecommendHR %></td>
						<td><%= totalRecommend %></td>
						<td><%= realizationPlan %>%</td>
						<td><%= numberOfConfirms %></td>
						<td><%= numberOfPesels %></td>
					</tr>
				<%} %>
				<tr style="background-color: #d8d8d8; font-style: italic; font-weight: bold;" >
					<% double sumOfRealization = pM.getRealizationOfPlan(sumOfConfirms, sumOfSurveys); %>
					<td >Suma</td>
					<td><%= sumOfSurveys %></td>
					<td><%= sumOfSurveysHr %></td>
					<td><%= sumOfTotalSurveys %></td>
					<td><%= sumOfRecommend %></td>
					<td><%= sumOfRecommendHR %></td>
					<td><%= sumOfTotalRecommend %></td>
					<td><%= sumOfRealization %>%</td>
					<td><%= sumOfConfirms %></td>
					<td><%= sumOfPesels %></td>
				</tr>
			</tbody>	
		</table>
		</div>
</body>
</html>
	

